package com.teng.mrliuproject.ui.activity

import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.teng.mrliuproject.R
import com.teng.mrliuproject.base.RouteManages
import com.teng.mrliuproject.databinding.ActivityMainBinding
import com.teng.mrliuproject.ui.vmodel.MainVModel
import com.teng.mylibrary.base.BaseActivity
import com.teng.mylibrary.widget.InteractionDialog
import com.teng.mrliuproject.base.Global
import com.teng.mylibrary.util.SPUtil
import com.teng.mylibrary.util.update.UpdateAppUtil


@Route(path = RouteManages.MAIN_ACTIVITY)
class MainActivity : BaseActivity<ActivityMainBinding, MainVModel>() {


    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_main
    }

    override fun initViewModel(): MainVModel {
        return ViewModelProvider(this).get(MainVModel::class.java)
    }

    override fun isTranslucentSutatus(): Boolean {
        return true
    }

    override fun onResume() {
        super.onResume()
    }

    override fun initView() {
        binding.viewmodel = viewModel
        supportActionBar?.hide()

        viewModel.myUc.showActionTextEvent.observe(this, {
            val dialog = InteractionDialog(it)
            dialog.setOnConfirmClickListener {
                ARouter.getInstance().build(RouteManages.LOGIN_ACTIVITY).navigation()
                finish()
            }
            dialog.showNow(supportFragmentManager, null)
        })
    }

    override fun initData() {
//        UpdateAppUtil.checkUpdate(this, SPUtil.getIp() + Global.UPDATE_URL)
        viewModel.appVersion.set("v${packageManager.getPackageInfo(packageName, 0).versionName}")
    }


}